<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/sys/include/taglib.jsp" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<%@ include file="/WEB-INF/adminui/include/css.jsp" %>
<title>权限列表</title>
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content ">
	<div class="row">
		<div class="col-sm-2" style="width:20%">
			<div class="ibox ibox-body">
				<div class="ibox-title">
					<h5>选择园区</h5>
				</div>
				<div class="ibox-content">
					<div id="jstree"></div>
				</div>
			</div>
		</div>
		<div class="col-sm-9">
			<div class="ibox">
				<div class="ibox-body">
					<div class="fixed-table-toolbar">
						<div id="toolbar_PARK" class="columns pull-left uilist-toolbar uilist-toolbar-PARK">
							<button type="button" class="btn btn-primary" onclick="add()">
								<i class="fa fa-plus hidden" aria-hidden="true"></i>添加
							</button>
							<button type="button" class="btn btn-danger multi" onclick="del()">
								<i class="fa fa-trash hidden" aria-hidden="true"></i>删除
							</button>
						</div>
						<div id="toolbar_BLOCK" class="columns pull-left uilist-toolbar uilist-toolbar-BLOCK" style="display:none;">
							<button type="button" class="btn btn-primary" onclick="addP()">
								<i class="fa fa-plus hidden" aria-hidden="true"></i>添加P
							</button>
							<button type="button" class="btn btn-danger multi" onclick="delP()">
								<i class="fa fa-trash hidden" aria-hidden="true"></i>删除P
							</button>
						</div>
						
						<div class="columns pull-right">
							<button class="btn btn-success" onclick="UiList.loadTable()">查询</button>
						</div>
						
						<div class="columns pull-right col-md-2 nopadding uilist-search uilist-search-PARK">
							<input id="searchName" type="text" class="form-control" placeholder="按名称查询">
						</div>
						
						<div class="columns pull-right nopadding uilist-search uilist-search-BLOCK" style="width:150px;">
							<input id="end" type="text" class="laydate-icon form-control" placeholder="结束日期">
						</div>
						<div class="columns pull-right nopadding uilist-search uilist-search-BLOCK" style="vertical-align:middle;height:34px;line-height:34px;padding:0 5px;">至</div>
						<div class="columns pull-right nopadding uilist-search uilist-search-BLOCK" style="width:150px;">
							<input id="begin" type="text" class="laydate-icon form-control" placeholder="开始日期">
						</div>
						
					</div>
					<table id="dataTable" data-mobile-responsive="true">
					</table>
				</div>
			</div>
		</div>
	</div>
</div>
<%@ include file="/WEB-INF/adminui/include/script.jsp" %>
<script type="text/javascript">
$(function(){
	laydate({ 
		elem: '#begin'
	});
	laydate({ 
		elem: '#end'
	});
	UiList.render({
		treeUrl: '${path}/parkjstree/menudata.json?module=plant',
		multiTableSupport: true,
		multiTableConfig:{
			PARK:{
				url: "${path}/block/listdata.json",
				idfield: 'blockid',
				toolbar: 'toolbar_PARK',
				columns: [
					{checkbox : true},
					{field : 'blockName', title : '地块名称'},
					{field : 'blockCode', title : '地块编号'},
					{field : 'area', title : '地块面积(m²)'},
					{field : 'isuse', title : '地块状态', formatter : function(value, row, index) {
						switch(''+value){
						case '0': return '闲置';
						case '1': return '正常';
						}
						return ''+value;
					}},
					{field : 'blockid', title : '操作', align : 'center', formatter : function(value, row, index) {
						var s = '';
						<qx:perm code="park_BLOCK_EDIT">
						s += '<a class="btn btn-primary btn-sm" href="javascript:;" title="修改" onclick="edit(\''+value+'\')"><i class="fa fa-edit"></i></a>';
						</qx:perm>
						return s;
					}}
				]
			},
			BLOCK:{
				url: "${path}/plant/listdata.json",
				idfield: 'plantid',
				toolbar: 'toolbar_BLOCK',
				columns: [
					{checkbox : true},
					{field : 'blockName', title : '地块名称'},
					{field : 'cropName', title : '种植作物'},
					{field : 'beginTime', title : '种植日期', formatter : function(value, row, index) {
						return formatDate(value, 'yyyy-MM-dd');
					}},
					{field : 'endTime', title : '成熟日期', formatter : function(value, row, index) {
						return formatDate(value, 'yyyy-MM-dd');
					}},
					{field : 'isCurrent', title : '当前作物', formatter : function(value, row, index) {
						switch(''+value){
						case '0': return '历史作物';
						case '1': return '当前作物';
						}
						return ''+value;
					}},
					{field : 'plantStatus', title : '作物状态', formatter : function(value, row, index) {
						switch(''+value){
						case '0': return '未成熟';
						case '1': return '已成熟';
						}
						return ''+value;
					}},
					{field : 'isuse', title : '地块状态', formatter : function(value, row, index) {
						switch(''+value){
						case '0': return '闲置';
						case '1': return '正常';
						}
						return ''+value;
					}},
					{field : 'plantid', title : '操作', align : 'center', formatter : function(value, row, index) {
						var s = '';
						<qx:perm code="plant_PLANT_EDIT">
						s += '<a class="btn btn-primary btn-sm" href="javascript:;" title="修改" onclick="editP(\''+value+'\')"><i class="fa fa-edit"></i></a>';
						</qx:perm>
						return s;
					}}
				]
			}
		},
		tableParams: function(){//搜索条件
			var type = this.selectedTreeNode.type;
			if(type == 'PARK'){
				return {blockName: $("#searchName").val()};
			}else{
				return {begin: $("#begin").val(), end: $("#end").val()};
			}
		}
	});
	
});

function add(){
	UiList.open('${path}/block/add.do', '添加地块信息');
}
function del(){
	UiList.dialog('${path}/block/delete.json', '您确定要删除选中的地块信息吗？', '删除地块信息成功.');
}
function edit(id){
	UiList.open('${path}/block/edit.do?blockid='+id, '修改地块信息');
}

function addP(){
	UiList.open('${path}/plant/add.do', '添加种植信息');
}
function delP(){
	UiList.dialog('${path}/plant/delete.json', '您确定要删除选中的种植信息吗？', '删除种植信息成功.');
}
function editP(id){
	UiList.open('${path}/plant/edit.do?plantid='+id, '修改种植信息');
}
</script>
</body>
</html>